package com.xiao.controller;

import com.xiao.domain.ResponseResult;
import com.xiao.domain.dto.AddRoleDto;
import com.xiao.domain.dto.RoleChangeStatusDto;
import com.xiao.domain.dto.SysRoleDto;
import com.xiao.domain.vo.AllRoleListVo;
import com.xiao.domain.vo.PageVo;
import com.xiao.domain.vo.RoleMenuDto;
import com.xiao.domain.vo.SysRoleByIdVo;
import com.xiao.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
@Api(tags = "用户角色")
public class SysRoleController {
    @Autowired
    SysRoleService sysRoleService;

    @GetMapping("/list")
    @ApiOperation("返回查询的角色列表,带分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
            @ApiImplicitParam(name = "sysRoleDto",value = "接收参数-DTO")
    })
    public ResponseResult<PageVo> roleList(Integer pageNum,Integer pageSize,  SysRoleDto sysRoleDto){

        ResponseResult<PageVo> result = sysRoleService.roleList(pageNum,pageSize,  sysRoleDto);

        return result;
    }




    @PutMapping("/changeStatus")
    @ApiOperation("通过角色ID,修改角色的状态")
    @ApiImplicitParam(name = "roleChangeStatus",value = "提交响应的,dto")
    public ResponseResult roleChangeStatus(@RequestBody  RoleChangeStatusDto roleChangeStatusDto){// @RequestBody 获取请求体

        ResponseResult responseResult = sysRoleService.roleChangeStatus(roleChangeStatusDto);

        return responseResult;
    }

    @PostMapping
    @ApiOperation("新增角色")
    @ApiImplicitParam(name = "addRoleDto",value = "前端来的请求体")
    public ResponseResult addRole(@RequestBody AddRoleDto addRoleDto){// 接收前端 请求体

        ResponseResult responseResult = sysRoleService.addRole(addRoleDto);

        return responseResult;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID列表,删除角色")
    @ApiImplicitParam(name = "id",value = "角色ID")
    public ResponseResult delRole(@PathVariable("id") List<Long> ids){// 接收前端 请求体

        ResponseResult responseResult = sysRoleService.delRoleById(ids);

        return responseResult;
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id，获取角色")
    @ApiImplicitParam(name = "id",value = "角色id")
    public ResponseResult<SysRoleByIdVo> getRoleById(@PathVariable("id") Long id){ // restful /{id}请求;需要指定参数

        ResponseResult<SysRoleByIdVo> result = sysRoleService.getRoleById(id);

        return result;
    }

    @PutMapping
    @ApiOperation("根据请求体,修改角色信息，及其角色菜单关系")
    @ApiImplicitParam(name = "roleMenuDto",value = "请求体，包含 角色信息，及其角色菜单ID列表")
    public ResponseResult updateRoleMenu(@RequestBody RoleMenuDto roleMenuDto){
        ResponseResult responseResult = sysRoleService.updateRoleMenu(roleMenuDto);
        return responseResult;
    }


    @GetMapping("/listAllRole")
    @ApiOperation("获取所有状态正常的角色列表")
    public ResponseResult getAllRoleList(){
        // 1. 调用 service
        List<AllRoleListVo> allRoleList = sysRoleService.getAllRoleList();
        // 2. 统一响应
        ResponseResult responseResult = ResponseResult.okResult(allRoleList);

        return responseResult;

    }

}
